package com.hmsg.health.dao;


import com.hmsg.health.bean.domain.TaskDo;
import com.hmsg.health.bean.domain.TaskTypeDo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface TaskTypeDao {

    @Insert("<script>" +
            "insert into `s_task_type` " +
            "  <set>" +
            "    <if test='info.name != null'>" +
            "     `name` = #{info.name}, " +
            "    </if>" +
            "    <if test='info.icon != null'>" +
            "     `icon` = #{info.icon}, " +
            "    </if>" +
			"    <if test='info.detail != null'>" +
			"     `detail` = #{info.detail}, " +
			"    </if>" +
			"    <if test='info.status != null'>" +
			"     `status` = #{info.status}, " +
			"    </if>" +
			"    <if test='info.image != null'>" +
			"     `image` = #{info.image}, " +
			"    </if>" +
			"    <if test='info.parentId != null'>" +
			"     `parent_id` = #{info.parentId}, " +
			"    </if>" +
			"    <if test='info.tepOne != null'>" +
			"     `tep_one` = #{info.tepOne}, " +
			"    </if>" +
			"    <if test='info.tepTwo != null'>" +
			"     `tep_two` = #{info.tepTwo}, " +
			"    </if>" +
			"    <if test='info.slogan != null'>" +
			"     `slogan` = #{info.slogan}, " +
			"    </if>" +
            "  </set>" +
            "</script>")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int save(@Param("info") TaskTypeDo info);


    @Select("select * from s_task_type where id=#{id}")
    TaskTypeDo findOne(@Param("id") Integer id);

    @Select("<script>" +
    	    "select * from  `s_task_type` where 1=1 " +
    	    "    <if test='info.id != null'>" +
    	    "     and `id` = #{info.id} " +
    	    "    </if>" +

    	    "    <if test='info.status != null'>" +
    	    "    and  `status` = #{info.status} " +
    	    "    </if>" +
    	    "    <if test='info.parentId != null'>" +
    	    "    and  `parent_id` = #{info.parentId} " +
    	    "    </if>" +
    	    "</script>")
	List<TaskTypeDo> select(@Param("info") TaskTypeDo info);
    
    @Select("select * from  `s_task_type` where parent_id=#{parentId}")
	List<TaskTypeDo> selectByParentId(@Param("parentId") Integer parentId);
    
    @Select("select * from  `s_task_type` where parent_id != 0")
	List<TaskTypeDo> selectByParentIdIsNot();

    @Select("select * from s_task_type where parent_id !=0 ")
	List<TaskTypeDo> findAll();

	@Select("select * from s_task_type where parent_id =0 and `status`=1")
	List<TaskTypeDo> findQuery();


    @Select("select * from s_task_type where parent_id =#{parentId}  ")
    List<TaskTypeDo> queryTwoClass(@Param("parentId") Integer parentId);


	@Update({"<script>",
			"UPDATE  s_task_type",
			"<trim prefix='set' suffixOverrides=','>",
			"<if test='taskTypeDo.name!=null'>",
			"name= #{taskTypeDo.name},",
			"</if>",
			"<if test='taskTypeDo.status!=null'>",
			"status= #{taskTypeDo.status},",
			"</if>",
			"<if test='taskTypeDo.icon!=null'>",
			"icon= #{taskTypeDo.icon},",
			"</if>",
			"<if test='taskTypeDo.image!=null'>",
			"image= #{taskTypeDo.image},",
			"</if>",
			"<if test='taskTypeDo.parentId!=null'>",
			"parent_id= #{taskTypeDo.parentId},",
			"</if>",
			"<if test='taskTypeDo.tepOne!=null'>",
			"tep_one= #{taskTypeDo.tepOne},",
			"</if>",
			"<if test='taskTypeDo.tepTwo!=null'>",
			"tep_two= #{taskTypeDo.tepTwo},",
			"</if>",
			"<if test='taskTypeDo.slogan!=null'>",
			"slogan= #{taskTypeDo.slogan},",
			"</if>",

			"</trim>",
			"where id = #{taskTypeDo.id}",
			"</script>"})
	void update(@Param("taskTypeDo") TaskTypeDo taskTypeDo);


	@Delete("delete from s_task_type where id=#{taskTypeDo.id}")
	void delete(@Param("taskTypeDo") TaskTypeDo taskTypeDo);
}
